Skip to content

Conversation

@winner245
Copy link
Contributor

@winner245 winner245 commented Nov 25, 2024

The existing exceptions tests for vector<T> have several issues: some tests did not throw exceptions at all, making them not useless for exception-safety testing, and some tests did not throw exceptions at the intended points, failing to serve their expected purpose. This PR fixes all those tests. Morever, this PR extracted common classes and utilities into a separate header file, and renamed those classes using more descriptive names.

For your convenience, I have added comments on the problematic tests.

try { // Throw in vector(size_type, const allocator_type&) from allocator
throwing_allocator<int> alloc(false, true); // throw on copy only
AllocVec get_alloc(0, alloc);
} catch (int) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test did not throw.

int a[] = {1, 2};
Allocator<int> alloc(false);
throwing_allocator<int> alloc(false, true); // throw on copy only
AllocVec vec(cpp17_input_iterator<int*>(a), cpp17_input_iterator<int*>(a + 2), alloc);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test did not throw.

int a[] = {1, 2};
Allocator<int> alloc(false);
throwing_allocator<int> alloc(false, true); // throw on copy only
AllocVec vec(forward_iterator<int*>(a), forward_iterator<int*>(a + 2), alloc);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test did not throw.

int throw_after = 1;
vec.emplace_back(throw_after);
auto vec2 = vec;
} catch (int) {
Copy link
Contributor Author

@winner245 winner245 Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test threw in the emplace_back call, not in vector(const vector&).

throwing_t v(throw_after);
vec.insert(vec.end(), 6, v);
std::vector<throwing_t, test_allocator<throwing_t> > vec2(std::move(vec), test_allocator<throwing_t>(2));
} catch (int) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test did not throw.

@winner245 winner245 force-pushed the fix-vector-exception-tests branch 3 times, most recently from 977dd93 to d8ea0f9 Compare November 26, 2024 03:26
@winner245 winner245 force-pushed the fix-vector-exception-tests branch from d8ea0f9 to bf2a0b1 Compare November 26, 2024 03:36
@winner245 winner245 closed this Nov 26, 2024
@winner245 winner245 deleted the fix-vector-exception-tests branch November 26, 2024 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant